package com.lwy.qiuchao.field.service.impl;

import com.lwy.qiuchao.field.dao.CityDao;
import com.lwy.qiuchao.field.entity.CityEntity;
import com.lwy.qiuchao.field.entity.FieldInfoEntity;
import com.lwy.qiuchao.field.service.CityService;
import com.lwy.qiuchao.field.vo.FieldDetailInfoEntityVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lwy.common.utils.PageUtils;
import com.lwy.common.utils.Query;

import com.lwy.qiuchao.field.dao.FieldDao;
import com.lwy.qiuchao.field.entity.FieldEntity;
import com.lwy.qiuchao.field.service.FieldService;


@Service("fieldService")
public class FieldServiceImpl extends ServiceImpl<FieldDao, FieldEntity> implements FieldService {

    @Autowired
    FieldService fieldService;

    @Autowired
    CityDao cityDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<FieldEntity> page = this.page(
                new Query<FieldEntity>().getPage(params),
                new QueryWrapper<FieldEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public String getFieldName(Long fieldId) {

        return this.baseMapper.getFieldName(fieldId);
    }

    @Override
    public void addField(FieldEntity fieldEntity) {
        CityEntity cityEntity = cityDao.selectOne(new QueryWrapper<CityEntity>().eq("city_id", fieldEntity.getCityId()));
        if(cityEntity!=null){
            this.baseMapper.insert(fieldEntity);
            cityEntity.setFieldCount(cityEntity.getFieldCount()+1);
            cityDao.updateById(cityEntity);
        }
    }



}